﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;


namespace Deviseur_Cs2i_Car
{
    public partial class AdminCategOption : Form
    {
        public AdminCategOption()
        {
            InitializeComponent();
        

            Thread TypeThread = new Thread(new ThreadStart(getAllCategOption_Thread));
            TypeThread.Start();
        }

        private void getAllCategOption_Thread()
        {
            Invoke(new MethodInvoker(getAllCategOption));
        }

        private void getAllCategOption()
        {
            Table CategOption = Program.Db.QueryTable("SELECT * FROM CATEGOPTION");

            this.dataCategOption.Rows.Clear();

            foreach (Record r in CategOption)
                this.dataCategOption.Rows.Add(r.Values[0], r.Values[1]);
        }

        private void AdminCategOption_Activated(object sender, EventArgs e)
        {
            Thread TypeThread = new Thread(new ThreadStart(getAllCategOption_Thread));
            TypeThread.Start();
        }

        private void buttonAddCategOption_Click(object sender, EventArgs e)
        {
            AddCategOption FenAddCategOption = new AddCategOption();
            FenAddCategOption.ShowDialog();
        }

        private void buttonDelCategOption_Click(object sender, EventArgs e)
        {
            CATEGOPTION delCategOption = new CATEGOPTION();
            delCategOption.delete_CategOption(Convert.ToInt32(this.dataCategOption.SelectedRows[0].Cells[0].Value.ToString()));
            Thread CategOptionThread = new Thread(new ThreadStart(getAllCategOption_Thread));
            CategOptionThread.Start();
        }

        private void buttonUpdateCategOption_Click(object sender, EventArgs e)
        {
            AddCategOption FenAddCategOption = new AddCategOption(Convert.ToInt32(this.dataCategOption.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddCategOption.ShowDialog();
        }
        

      }
}
